var jia=document.getElementsByClassName("jia");
var jian=document.getElementsByClassName("jian");
var qty=document.getElementsByClassName("qty");
var hdxj=document.getElementsByClassName("hdxj");
var dj=document.getElementsByClassName("dj");
var xj=document.getElementsByClassName("xj");
var danxuan=document.getElementsByClassName("danxuan");
var zongjia=document.getElementsByClassName("zongjia")[0];
var del=document.getElementsByClassName("del");
var con2_midd=document.getElementsByClassName("con2-midd");
var min_con2=document.getElementsByClassName("min-con2")[0];
var t=new Array(3);
t[0]=0;
t[1]=0;
t[2]=0;
//alert(t);
for(var i=0;i<jia.length;i++){
    jia[i].onclick=function(){
        for(var j=0;j<jia.length;j++){
            if(this==jia[j]){
                var num=qty[j].innerHTML;
                num++;
                qty[j].innerHTML=num;
                xj[j].innerHTML=num*parseFloat(dj[j].innerHTML);
                hdxj[j].innerHTML=num*parseFloat(dj[j].innerHTML);
                zongjiage();
                if(num>0){
                    jian[j].disabled=false;
                }
            }
        }
    }
    jian[i].onclick=function(){
        for(var j=0;j<jia.length;j++){
            if(this==jian[j]){
                var num=qty[j].innerHTML;
                num--;
                qty[j].innerHTML=num;
                xj[j].innerHTML=num*parseFloat(dj[j].innerHTML);
                hdxj[j].innerHTML=num*parseFloat(dj[j].innerHTML);
                zongjiage();
                if(num==0){
                    jian[j].disabled=true;
                }
            }
        }
    }
    danxuan[i].onclick=function(){
        for(var j=0;j<danxuan.length;j++){
            if(this==danxuan[j]){
                if(danxuan[j].checked){
                    t[j]=1;
               }else{
                    t[j]=0;
                }
                zongjiage();
            }
        }
    }
}
for(var i=0;i<del.length;i++){
    del[i].onclick=function(){
        for(var j=0;j<del.length;j++){
            if(this==del[j]){
                min_con2.removeChild(con2_midd[j]);
            }
        }
        zongjiage();
    }
}
function zongjiage(){
    var num1=0;
    console.log(num1);
    for(var x=0;x<hdxj.length;x++){
        num1+=parseFloat(t[x]*hdxj[x].innerHTML);
    }
    //num1=t[0]*hdxj[0].innerHTML+t[1]*hdxj[1].innerHTML+t[2]*hdxj[2].innerHTML;
    zongjia.innerHTML=num1;
}
